package com.supermap.application.utils;

import java.util.Map;

/**
 * @ClassName TableBuilderUtils
 * @Description 动态建表工具类
 * @Author HEKE
 * @Date 2019/3/2 18:34
 */
public class TableBuilderUtils {

    /**
     * 根据表名动态创建目标体系指标数据表
     * @param tablename
     * @return
     */
    public static String createTargetIndexSysTable(String tablename){
        String sql = "create table "+tablename+"\n" +
                "(\n" +
                "  index_code_     VARCHAR2(100),\n" +
                "  index_name_     VARCHAR2(100),\n" +
                "  diqu_           VARCHAR2(100),\n" +
                "  diqu_name_      VARCHAR2(50),\n" +
                "  jh_wcl_         NUMBER(10,2),\n" +
                "  jh_zs_          NUMBER(10,2),\n" +
                "  sj_wcl_         NUMBER(10,2),\n" +
                "  sj_zs_          NUMBER(10,2),\n" +
                "  time_           VARCHAR2(6),\n" +
                "  id_             VARCHAR2(100),\n" +
                "  score_          NUMBER(10),\n" +
                "  editor_context_ VARCHAR2(4000)\n" +
                ")";

        return sql;
    }

    /**
     * 上传数据
     * @param tablename
     * @param rowDatas
     * @return
     */
    public static String insetIntoTargetIndexSysTable(String tablename, Map<String, Object> rowDatas){
        String index_code_ = rowDatas.get("INDEX_CODE_") + "";
        String index_name_ = rowDatas.get("INDEX_NAME_") + "";
        String diqu_ = rowDatas.get("DIQU_") + "";
        String diqu_name_ = rowDatas.get("DIQU_NAME_") + "";
        String time_ = rowDatas.get("TIME_") + "";

        String jhwcl = rowDatas.get("JH_WCL_") + "";
        double jh_wcl_;
        if (jhwcl.equals("") || jhwcl.equals("null")){
            jh_wcl_ = 0;
        } else {
            jh_wcl_ = Double.parseDouble(jhwcl.trim());
        }

        String jhzs = rowDatas.get("JH_ZS_") + "";
        double jh_zs_ ;
        if (jhzs.equals("") || jhwcl.equals("null")){
            jh_zs_ = 0;
        }else {
            jh_zs_ = Double.parseDouble(jhzs.trim());
        }

        String sjwcl = rowDatas.get("SJ_WCL_") + "";
        double sj_wcl_;
        if (sjwcl.equals("") || sjwcl.equals("null")){
            sj_wcl_ = 0;
        }else {
            sj_wcl_ = Double.parseDouble(sjwcl.trim());
        }

        String sjzs = rowDatas.get("SJ_ZS_") + "";
        double sj_zs_;
        if (sjzs.equals("") || sjzs.equals("null")){
            sj_zs_ = 0;
        }else {
            sj_zs_ = Double.parseDouble(sjzs.trim());
        }


        String score = rowDatas.get("SCORE_") + "";
        double score_;
        if (score.equals("") || score.equals("null")){
            score_ = 0;
        }else {
            score_ = Double.parseDouble(score.trim());
        }

        String sql = "insert into " + tablename + " (INDEX_CODE_,INDEX_NAME_,DIQU_, " + " DIQU_NAME_,JH_WCL_,JH_ZS_,SJ_WCL_,SJ_ZS_,TIME_,SCORE_)  values" + "('"+index_code_+"','"+index_name_+"','"+diqu_+"','"+diqu_name_+"',"+jh_wcl_+","+jh_zs_+","+sj_wcl_+","+sj_zs_+",'"+time_+"',"+score_+")";
        return sql;
    }
}
